package com.jie.netty.im.tactics.impl;

import com.jie.constants.ChannelAttrKey;
import com.jie.netty.im.tactics.HeartbeatTimeoutHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.util.AttributeKey;
import lombok.extern.slf4j.Slf4j;

/**
 * 登录心跳超时处理类
 */
@Slf4j
public class LoginHeartbeatTimeoutHandler implements HeartbeatTimeoutHandler {

    @Override
    public void handleTimeout(ChannelHandlerContext ctx) {
        AttributeKey<String> attr = AttributeKey.valueOf(ChannelAttrKey.USER_NAME);
        String username = ctx.channel().attr(attr).get();
        AttributeKey<Integer> terminalAttr = AttributeKey.valueOf(ChannelAttrKey.TERMINAL_TYPE);
        Integer terminal = ctx.channel().attr(terminalAttr).get();
        log.info("登录心跳超时，即将断开连接,用户:{},终端类型:{} ", username, terminal);
    }
}